package com.peanut.boot.controller;

import com.peanut.boot.common.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

//@Api用在请求的类上，表示对类的说明 tags说明该类的作用，可以在UI界面上看到注解
@Api(tags = "订单管理接口")
@RestController
@RequestMapping("/order")
public class OrderController {
    /*
    @ApiImplicitParams: 用在请求的方法上，说明方法的用途，作用
        @ApiImplicitParam：用在@ApiImplicitParams注解中，指定一个请求参数的各个方面
            name:参数名
            value:参数的汉字说明，解释
            required:参数是否必须传
            paramType:参数放在哪个地方
                · header --> 请求参数的获取：@RequestHeader
                · query --> 请求参数的获取：@RequestParam
                · path（用于restful接口）--> 请求参数的获取：@PathVariable
                · body（不常用）
                · form（不常用）
            dataType:参数类型，默认String,其他值dataType="Integer"
            defaultValue:参数的默认值
     */
    @Operation(summary = "提交订单")
    @PostMapping("/order")
    @ApiImplicitParams({
//            @ApiImplicitParam(
//                    name = "userId",
//                    value = "用户Id",
//                    required = true,
//                    dataTypeClass = Long.class,
//                    //example实例参数
//                    paramType = "query", example = "123"),
//            @ApiImplicitParam(
//                    name = "goodsId",
//                    value = "商品Id",
//                    dataTypeClass = Integer.class,
//                    paramType = "query", example = "1")
    })
    public CommonResult<String> toBuy(@ApiIgnore @RequestParam Map<String, String> params) {
        System.out.println(params);
        return CommonResult.success("success");
    }



    @Operation(summary = "获取订单集合接口")
    @GetMapping("/order/{name}")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "name",
                    value = "一个傻瓜",
                    dataTypeClass = String.class,
                    paramType = "path", example = "傻瓜"),

            @ApiImplicitParam(
                    name = "quantity",
                    value = "你要几个商品",
                    dataTypeClass = Integer.class,
                    paramType = "query", example = "2"),
    })
    public CommonResult<String> getTask(@PathVariable("name") String name,
                                        @ApiIgnore @RequestParam Map<String, String> params) {
        System.out.println(params);
        System.out.println(name);
        return CommonResult.success("success");
    }

}

